<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<head>
	<jsp:include page="commons.jsp"></jsp:include>
	<script type="text/javascript">
		var selected = 0;
		$(function(){
			$('#edition-div').modalpop({beforeShow:fill_edition,afterClose:clean_edition,action:save_currency});
		});
		
		function fill_edition(){
			$('#currency_id').text($('#currency_'+selected + ' td[name="id"]').text());
			$('#currency_name').val($('#currency_'+selected + ' td[name="name"]').text());
			$('#currency_symbol').val($('#currency_'+selected + ' td[name="symbol"]').text());
		}
		
		function clean_edition(){
			$('#edition-div input').each(function(){$(this).val('')});
		}
		
		function save_currency(){
			alert('save');
		}
	</script>
	
</head>

<table class="table">
	<tr>
		<th>
			Id
		</th>
		<th>
			Name
		</th>
		<th>
			Symbol
		</th>
		<th>
			Actions
		</th>
	</tr>
	<c:forEach items="${currencies}" var="currency" varStatus="status">
		<tr id="currency_${status.index}">
			<td name="id">${currency.id}</td>
			<td name="name">${currency.name}</td>
			<td name="symbol">${currency.symbol}</td>
			<td><a class="tiny-button-class" id="edit" onclick="selected = ${status.index}; $('#edition-div').modalpop('open');">editar</a><a class="tiny-button-class" id="delete">eliminar</a></td>
		</tr>
	</c:forEach>
	
</table>
<div id="edition-div" class="form">
	<input type="hidden" id="currency_id"/>
	<div class="form_row">
		<div class="name"><label>Name</label></div>
		<div><input type="text" id="currency_name"/></div>
	</div>
	<div class="form_row">
		<div class="name"><label>Symbol</label></div>
		<div><input type="text" id="currency_symbol"/></div>
	</div>
</div>
